home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / EXETOCOM.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  134 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3.  
  4. ; Copyright 1983 Data Base Decisions
  5. ; This program is used as a header for an EXE file to load it
  6. ; faster. It is copied onto the front of an EXE file as follows:
  7. ; copy exetocom.bin/b+prog.exe/b newprog.com, where prog.exe is your
  8. ; program. The resulting COM file must be less than 64K.
  9.  
  10. jumploc equ 0efh        ; jump to psp for copy
  11.  
  12. exetocom proc far
  13.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  14.  
  15.     mov si,offset endprog    ; end of this prog
  16.     mov ax,[si]        ; get EXE signature
  17.     cmp ax,5a4dh        ; exe file?
  18.     jz p010         ; yes
  19.     mov dx,offset errmsg1
  20.  
  21. p005:    mov ah,9
  22.     int 21h
  23.     int 20h         ; terminate
  24.  
  25. p010:
  26.     mov ax,si
  27.     mov cl,4
  28.     shr ax,cl        ; # of pghs in this prog
  29.     mov bx,ds
  30.     add ax,bx        ; seg of exe header
  31.     add ax,[si+8]        ; plus header size (pghs)
  32.     mov oseg,ax        ; gives orig exe start seg
  33.  
  34.     mov ax,cs        ; get new exe start seg
  35.     add ax,10h
  36.     mov nseg,ax
  37.  
  38.     mov ax,[si+10h]     ; check stack placement
  39.     mov cl,4        ; get stack size
  40.     shr ax,cl        ; convert to pghs
  41.     add ax,nseg        ; add base seg
  42.     add ax,[si+0eh]     ; and sp offset
  43.     mov bx,2
  44.     mov bx,[bx]        ; get top of memory
  45.     cmp bx,ax        ; room for the stack?
  46.     jae p015        ; yes
  47.     mov dx,offset errmsg2
  48.     jmp p005
  49.  
  50. p015:    mov ax,nseg
  51.     mov bx,si
  52.     add bx,[si+18h]     ; first relocation item
  53.     mov cx,[si+6]        ; # of items
  54.     jcxz p030        ; none
  55.  
  56. p020:    mov dx,[bx+2]        ; get code seg
  57.     add dx,oseg        ; add old start seg
  58.     mov es,dx        ; in es
  59.     mov di,[bx]        ; set instruction in es
  60.     add es:[di],ax        ; add new start seg
  61.     add bx,4        ; do another
  62.     loop p020        ; done?
  63.  
  64. p030:    push si         ; pass control
  65.     push cs
  66.     pop es            ; set es = cs
  67.     mov di,jumploc        ; copy copycode to psp
  68.     mov si,offset copycode
  69.     mov cx,17
  70.     rep movsb
  71.     pop si
  72.  
  73.     mov ax,nseg        ; new prog seg
  74.     add ax,[si+16h]     ; plus cs offset gives new cs
  75.     push ax         ; save it
  76.     mov ax,[si+14h]     ; new ip
  77.     push ax         ; save it
  78.  
  79.     push ds         ; save ds & es
  80.     push ds
  81.  
  82.     mov ax,nseg        ; new prog seg
  83.     mov es,ax        ; point to new seg
  84.     xor di,di        ; offset 0
  85.  
  86.     add ax,[si+0eh]     ; plus stack seg offset
  87.     push ax         ; save new ss
  88.     mov ax,[si+10h]     ; set sp
  89.     push ax         ; save it
  90.  
  91.     mov bx,[si+4]        ; get exe size (pages)
  92.     mov ax,[si+8]        ; get header size (pghs)
  93.     mov cl,5
  94.     shr ax,cl        ; convert pghs to pages
  95.     sub bx,ax        ; prog size (pages)
  96.     mov cl,8
  97.     shl bx,cl        ; convert pages to words
  98.     mov cx,bx        ; repeat count for copy
  99.  
  100.     mov ax,oseg
  101.     mov ds,ax        ; point to old seg
  102.     xor si,si        ; offset 0
  103.  
  104.     mov bx,jumploc
  105.     jmp bx            ; jump to copycode
  106.  
  107.     copycode equ this byte
  108.     rep movsw        ; copied code
  109.     pop ax            ; for sp
  110.     pop bx            ; for ss
  111.     pop es            ; restore es
  112.     pop ds            ; restore ds
  113.     pop cx            ; for ip
  114.     pop dx            ; for cs
  115.     cli
  116.     mov ss,bx        ; set new stack
  117.     mov sp,ax
  118.     sti
  119.     push dx         ; push cs & ip
  120.     push cx
  121.     ret 0            ; go to the exe prog
  122.  
  123. errmsg1 db 'EXE header not found',10,13,'$'
  124. errmsg2 db 'Program too large',10,13,'$'
  125.  
  126. oseg    dw 0            ; original exe prog seg
  127. nseg    dw 0            ; new prog seg
  128.  
  129. endprog equ this word        ; must be on a paragraph boundary!
  130.  
  131. exetocom endp
  132. cseg    ends
  133. end    exetocom
  134.